home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1997: The Complete Utilities Toolkit / macworld-complete-utilities-1997.iso / Programming / Little Smalltalk v3.1.5 / C Source / Sources / CTextPane.cp < prev    next >
Encoding:
Text File  |  1995-06-25  |  5.8 KB  |  194 lines  |  [TEXT/KAHL]

  1. //=============================================================================
  2. //    Little Smalltalk, version 3
  3. //    Written by Tim Budd, Oregon State University, July 1988
  4. //
  5. //    Symantec Think Class Library interface code 
  6. //        ©Julian Barkway, April 1994, all rights reserved.
  7. //
  8. //    CTextPane.cp
  9. //    ------------
  10. //    This class implements a text-only pane.
  11. //
  12. //    
  13. //    Version History
  14. //    ---------------
  15. //    3.1.4 - First general release
  16. //    3.1.5 - Modified to support command-key equivalents for menu items
  17. //=============================================================================
  18.  
  19. #include <string.h>
  20. #include "CTextPane.h"
  21. #include "Commands.h"
  22. #include "CLStDoc.h"
  23. #include "CLStWindow.h"
  24. #include "CBartender.h"
  25. #include "CLStApp.h"
  26. #include "Constants.h"
  27. #include <Global.h>
  28. #include "TCLUtilities.h"
  29.  
  30. extern    CLStApp        *gSmalltalk;
  31. extern    CBartender    *gBartender;
  32. extern     EventRecord  gLastMouseUp;
  33. extern     CBureaucrat    *gGopher;    
  34.  
  35. #define DOC_DIRTY    ((CDocument *)itsSupervisor)->dirty
  36.  
  37. //={OVERRIDE}==================================================================
  38. // Initialise a shiny new text pane object.
  39. //=============================================================================
  40. void CTextPane::ITextPane (CView *encl, CBureaucrat *super, 
  41.                             SizingOption hSizing, SizingOption vSizing,
  42.                             short lineLength)
  43. {
  44.     Rect    margin = {4, 4, 0, 0};
  45.     
  46.     IEditText      (encl, super, 1, 1, 0, 0, hSizing, vSizing, 2000);
  47.     FitToEnclosure (TRUE, TRUE);
  48.     ResizeFrame    (&margin);
  49. }
  50.  
  51.  
  52. //={OVERRIDE}==================================================================
  53. // Stop a click selecting text when it is combined with the option key.
  54. //=============================================================================
  55. void CTextPane::DoClick (Point hitPt, short modifierKeys, long when)
  56. {     
  57.     if (modifierKeys & optionKey)
  58.         return;
  59.  
  60.     inherited::DoClick (hitPt, modifierKeys, when);        
  61. }
  62.  
  63.  
  64. //={OVERRIDE}==================================================================
  65. // Handle menu dimming for cut'n'paste and ensure TCL commands aren't sent to
  66. // Smalltalk.
  67. //=============================================================================
  68. void CTextPane::DoCommand (long aCmd)
  69. {
  70.     if (aCmd == cmdPaste || aCmd == cmdCut)
  71.         if (! DOC_DIRTY) {
  72.             DOC_DIRTY = TRUE;
  73.             gBartender->EnableCmd (cmdSave);
  74.             gBartender->EnableCmd (cmdSaveAs);
  75.         }
  76.  
  77.     gSmalltalk->smalltalkCmd = FALSE;
  78.     inherited::DoCommand (aCmd);
  79.     if (! gSmalltalk->smalltalkCmd)
  80.          gSmalltalk->lastEvent.what = 0;
  81. }
  82.  
  83.  
  84. //={OVERRIDE}==================================================================
  85. // Ensure doc is set to be saved when an alphanumeric key has been pressed
  86. // v3.1.5: Ensure command key equivalents are processed
  87. //=============================================================================
  88. void CTextPane::DoKeyDown (char ch, Byte keyCde, EventRecord *event)
  89. {
  90.     inherited::DoKeyDown (ch, keyCde, event);
  91.  
  92.     switch (keyCde) {
  93.         case KeyHome:
  94.         case KeyEnd:
  95.         case KeyPageUp:
  96.         case KeyPageDown:
  97.             break;
  98.         default: 
  99.             if (! DOC_DIRTY) {
  100.                 DOC_DIRTY = TRUE;
  101.                 gBartender->EnableCmd (cmdSave);
  102.                 gBartender->EnableCmd (cmdSaveAs);
  103.             }
  104.             break;
  105.     }
  106. }
  107.  
  108.  
  109. //={OVERRIDE}==================================================================
  110. // Handle auto repeat
  111. //=============================================================================
  112. void CTextPane::DoAutoKey (char ch, Byte keyCde, EventRecord *event)
  113. {
  114.     inherited::DoAutoKey (ch, keyCde, event);
  115.  
  116.     switch (keyCde) {
  117.         case KeyHome:
  118.         case KeyEnd:
  119.         case KeyPageUp:
  120.         case KeyPageDown:
  121.             break;
  122.         default:  
  123.             if (! DOC_DIRTY) {
  124.                 DOC_DIRTY = TRUE;
  125.                 gBartender->EnableCmd (cmdSave);
  126.                 gBartender->EnableCmd (cmdSaveAs);
  127.             }
  128.             break;
  129.     }
  130. }
  131.  
  132.  
  133. //={OVERRIDE}==================================================================
  134. // Ensure correct action taken if new insertion will take TE to >32k.
  135. //=============================================================================
  136. void CTextPane::CheckInsertion (long insertLen, Boolean useSelection)
  137. {
  138.     long        newLen, growSize;
  139.     short        ln, svSelStart, svSelEnd, newSelEnd;
  140.     Handle        hdl;
  141.     
  142.     newLen = (**macTE).teLength + insertLen;    
  143.     if (useSelection)
  144.         newLen -= (**macTE).selEnd - (**macTE).selStart;
  145.     
  146.     if (newLen > kMaxTELength) {
  147.         svSelStart = (**macTE).selStart;
  148.         svSelEnd   = (**macTE).selEnd;
  149.         newSelEnd  = insertLen;
  150.         ln = FindLine (newSelEnd);    // Ensure we're deleting a full line
  151.         newSelEnd = (**macTE).lineStarts [ln + 1];
  152.         SetSelection (0, newSelEnd, FALSE);
  153.         TEDelete (macTE);
  154.         SetSelection (svSelStart, svSelEnd, FALSE);
  155.     }
  156. // Either delete enough from the top to make the insertion fit or post a recoverable 
  157. // error, depending on the parameters for this pane. At the moment, will always delete
  158. // from top. Shouldn't be editing big files in Little Smalltalk anyway....
  159.  
  160. //***Failure (paramErr, excExceedTELimit);    // Don't fail for now
  161.         
  162.     growSize = newLen - (**macTE).teLength;            // check for available memory
  163.     if (growSize > 0) {
  164.         hdl = NewHandleCanFail (growSize);
  165.         FailNIL      (hdl);
  166.         DisposHandle (hdl);
  167.     }
  168. }
  169.  
  170.  
  171. //=============================================================================
  172. // Replace the current contents of the text pane with theText.
  173. // Parameter changed type to Handle for v3.1.5 to provide better sizing for
  174. // TEInsert ().
  175. //=============================================================================
  176. void CTextPane::ReplaceContents (Handle theText)
  177. {
  178.     Prepare     ();
  179.     TESetSelect    (0L, 32767L, macTE);
  180.     TEDelete    (macTE);
  181.     TEInsert    ((char *)*theText, GetHandleSize (theText), macTE);
  182. }
  183.  
  184.  
  185. //=============================================================================
  186. // Completely delete the current contents of the text pane.
  187. //=============================================================================
  188. void CTextPane::DeleteContents (void)
  189. {
  190.     Prepare     ();
  191.     TESetSelect    (0L, 32767L, macTE);
  192.     TEDelete    (macTE);
  193. }
  194.